import * as proxy from '../proxy';
import ServiceBase from '../base';
import {
    FlowGroupListProxy,
    FlowGroupProxy,
    FlowPageProxy,
    FlowProxy,
    TaskPageProxy,
    FlowStageProxy,
    TaskProxy,
    TaskStageProxy,
    TaskEnclosureProxy,
    TaskToDoProxy,
    TaskCommentsProxy,
} from '../proxies/task-page-proxy';

const GET_PROCESS = '/process';
const GET_PROCESS_GROUPS = '/processGroups';
const GET_TASKS = '/tasks';

class TaskFlowService extends ServiceBase {
    // groups
    getProcessGroups = (data) => {
        let promise = super.get({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_PROCESS_GROUPS}`,
        });
        return proxy.httpResultProxy(promise, FlowGroupListProxy);
    };

    createdGroupName = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_PROCESS_GROUPS}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, FlowGroupProxy);
    };

    updateGroupName = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_PROCESS_GROUPS}/${data.id}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, FlowGroupProxy);
    };

    deleteGroupName = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_PROCESS_GROUPS}/${data.id}`,
        });
        return proxy.httpResultProxy(promise, FlowGroupProxy);
    };
    // process
    getProcess = (data) => {
        let promise = super.get({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_PROCESS}`,
            params: data.data,
        });
        return proxy.httpResultProxy(promise, FlowPageProxy);
    };
    //GET /accounts/{accountId}/projects/{projectId}/process/{processId} 根据 Id 获取 Process
    getProcessInfo = (data) => {
        let promise = super.get({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/${data.id}`,
        });
        return proxy.httpResultProxy(promise, FlowProxy);
    };
    createdProcess = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_PROCESS}`,
        });
        return proxy.httpResultProxy(promise, FlowProxy);
    };
    // DELETE /accounts/{accountId}/projects/{projectId}/process 删除指定的 Process
    deleteProcess = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_PROCESS}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    //DELETE /accounts/{accountId}/projects/{projectId}/process/{processId}/observers/{userId}  根据 id 移除抄送者
    deleteProcessUser = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/${data.processId}/observers/${data.userName}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    //PUT /accounts/{accountId}/projects/{projectId}/process/move/groups/{groupId} 移动 Process 到某个分组
    moveProcessToGroup = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/move/groups/${data.id}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, FlowProxy);
    };
    // /accounts/{accountId}/projects/{projectId}/process/{processId} 更新 Process
    updateProcess = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/${data.id}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, FlowProxy);
    };
    // POST /accounts/{accountId}/projects/{projectId}/process/{processId}/observer 更新(添加) Process 的抄送者
    addProcessObserver = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/${data.id}/observer`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, FlowProxy);
    };
    // POST /accounts/{accountId}/projects/{projectId}/process/copy 复制一个 Process
    copyProcess = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/copy`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    // stage
    // POST /accounts/{accountId}/projects/{projectId}/process/{processId}/stages  更新(添加) Process 的阶段
    addProcessStages = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/${data.id}/stages`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, FlowProxy);
    };
    // DELETE /accounts/{accountId}/projects/{projectId}/process/{processId}/stages/{stageId} 删除阶段
    deleteProcessStages = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/${data.processId}/stages/${data.stageId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    // Put /accounts/{accountId}/projects/{projectId}/process/{processId}/stages/{stageId}  更新 Process 下某一个 Stage
    updateProcessStage = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/${data.processId}/stages/${data.stageId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, FlowStageProxy);
    };
    // POST /accounts/{accountId}/projects/{projectId}/process/{processId}/stages/{stageId}/participants 给阶段新增执行者或抄送者
    addProcessStageParticipants = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/${data.processId}/stages/${data.stageId}/participants`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, FlowStageProxy);
    };
    // DELETE /accounts/{accountId}/projects/{projectId}/process/{processId}/stages/{stageId}/participants 移除阶段的执行者或抄送者
    deleteProcessStageParticipants = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/${data.processId}/stages/${data.stageId}/participants`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, FlowProxy);
    };
    // PUT /accounts/{accountId}/projects/{projectId}/process/{processId}/stages/{stageId}/order 更新 Stage 的排序
    moveProcessStageOrder = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/${data.processId}/stages/${data.stageId}/order`,
            data: data.data,
            headers: {'content-type': 'application/json'},
        });
        return proxy.httpResultProxy(promise);
    };
    // task GET /accounts/{accountId}/projects/{projectId}/tasks  获取当前 Project 下的 Task
    getTasks = (data) => {
        let promise = super.get({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_TASKS}`,
            params: data.data,
        });
        return proxy.httpResultProxy(promise, TaskPageProxy);
    };
    //POST  /accounts/{accountId}/projects/{projectId}/tasks 创建 Task
    createdTask = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks`,
        });
        return proxy.httpResultProxy(promise, TaskProxy);
    };
    // DELETE /accounts/{accountId}/projects/{projectId}/tasks 批量删除 Task
    deleteTask = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_TASKS}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    // PUT /accounts/{accountId}/projects/{projectId}/tasks/state 更新 Task 的状态
    updateTaskState = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_TASKS}/state`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    // GET /accounts/{accountId}/projects/{projectId}/tasks/{taskId} 获取当前 Project 下的 Task
    getTaskInfo = (data) => {
        let promise = super.get({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_TASKS}/${data.taskId}`,
        });
        return proxy.httpResultProxy(promise, TaskProxy);
    };
    // PUT /accounts/{accountId}/projects/{projectId}/tasks/{taskId} 更新 Task
    updateTask = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_TASKS}/${data.taskId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, TaskProxy);
    };
    // POST /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/observers 新增抄送者
    addTaskObservers = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_TASKS}/${data.taskId}/observers`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, TaskProxy);
    };
    // DELETE /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/observers 删除抄送者
    deleteTaskObservers = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}${GET_TASKS}/${data.taskId}/observers`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, TaskProxy);
    };
    // POST /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/stages/{stageId}/participants 给 Task 的阶段新增执行者或抄送者
    addParticipants = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/stages/${data.stageId}/participants`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, TaskStageProxy);
    };
    // DELETE /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/stages/{stageId}/participants 移除 Task 的阶段的执行者或抄送者
    deleteTaskParticipants = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/stages/${data.stageId}/participants`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, TaskStageProxy);
    };
    // DELETE /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/todo/{todoId}删除待办事项
    deleteTaskTodo = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/todo/${data.todoId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    // POST /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/todo新增待办事项
    createdTaskTodo = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/todo`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, TaskToDoProxy);
    };
    // POST /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/todo新增待办事项
    updateTaskTodo = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/todo/${data.todoId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, TaskToDoProxy);
    };
    // PUT /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/publish   Workflow 的'发布'操作
    publishTask = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/publish`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, TaskStageProxy);
    };
    // PUT /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/accept Workflow 的'通过'操作
    acceptTask = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/accept`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, TaskStageProxy);
    };

    // POST /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/comments 新增批注
    addTaskComments = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/comments`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, TaskCommentsProxy);
    };
    // DELETE /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/comments/{commentId} 删除批注
    deleteTaskComment = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/comments/${data.commentId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    // POST /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/enclosures 新增附件
    addEnclosures = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/enclosures`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise, TaskEnclosureProxy);
    };
    // DELETE /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/enclosures/{enclosureId} 删除附件
    deleteEnclosures = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/enclosures/${data.enclosureId}`,
        });
        return proxy.httpResultProxy(promise);
    };
    // PUT /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/reject Workflow 的'驳回'操作
    updateRejectTask = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/reject`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    // PUT /accounts/{accountId}/projects/{projectId}/tasks/{taskId}/transfer Workflow 的'移交'操作
    updateTransferTask = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/${data.taskId}/transfer`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };
    // POST /accounts/{accountId}/projects/{projectId}/tasks/search 根据条件获取当前Project下的Task
    getWorkFlowTasks = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/tasks/search`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    // GET /accounts/{accountId}/projects/{projectId}/workflowGroups  获取当前 Project 所有的 WorkflowGroup
    public getTaskGroups = (data) => {
        let promise = super.get({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/workflowGroups`,
            params: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    // GET /accounts/{accountId}/projects/{projectId}/workflowGroups/{groupId}  获取当前 Project ID 为 groupId 的 WorkflowGroup
    public getTaskGroupsById = (data) => {
        let promise = super.get({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/workflowGroups/${data.groupId}`,
            params: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    // POST /accounts/{accountId}/projects/{projectId}/workflowGroups  创建一个 Workflow 的 Group
    public createTaskGroupName = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/workflowGroups`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    // PUT /accounts/{accountId}/projects/{projectId}/workflowGroups/{groupId}  更新 WorkflowGroup
    public updateTaskGroupName = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/workflowGroups/${data.groupId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    // DELETE /accounts/{accountId}/projects/{projectId}/workflowGroups/{groupId}  删除指定的 WorkflowGroup
    public deleteTaskGroupName = (data) => {
        let promise = super.delete({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/workflowGroups/${data.groupId}`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    // PUT /accounts/{accountId}/projects/{projectId}/workflowGroups/{groupId}/move  移动指定的 WorkflowGroup
    public moveTaskGroupName = (data) => {
        let promise = super.put({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/workflowGroups/${data.groupId}/move`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    // GET /accounts/{accountId}/projects/{projectId}/processTemplate  获取流程模板的相关信息
    public getProcessTemplate = (data) => {
        let promise = super.get({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/processTemplate`,
            params: data.data,
        });
        return proxy.httpResultProxy(promise, FlowProxy);
    };

    // POST /accounts/{accountId}/projects/{projectId}/process/batch  根据流程信息批量创建流程
    public createImportFlows = (data) => {
        let promise = super.post({
            url: `/accounts/${data.accountId}/projects/${data.projectId}/process/batch`,
            data: data.data,
        });
        return proxy.httpResultProxy(promise);
    };

    // POST /Notifications 创建通知任务，探测到文件转换完成后创建分享并发送消息给用户
    public createNotifications = (data) => {
        const promise = super.post({
            data: data,
            url: '/notifications',
        });
        return proxy.httpResultProxy(promise);
    };
}

export {TaskFlowService};
